package com.example.societiesSystem.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.text.CharSequenceUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.societiesSystem.entity.SocietiesType;
import com.example.societiesSystem.entity.Teams;
import com.example.societiesSystem.mapper.SocietiesTypeMapper;
import com.example.societiesSystem.service.ISocietiesTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 社团类型 服务实现类
 * </p>
 *
 * @author 周欢
 * @since 2025-05-27
 */
@Service
public class SocietiesTypeServiceImpl extends ServiceImpl<SocietiesTypeMapper, SocietiesType> implements ISocietiesTypeService {

    @Override
    public IPage<SocietiesType> pageAll(Long pageIndex, Long pageSize, String name) {
        IPage<SocietiesType> page = new Page<>(pageIndex, pageSize);
        LambdaQueryWrapper<SocietiesType> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(CharSequenceUtil.isNotBlank(name), SocietiesType::getName, name);
        return this.page(page, queryWrapper);
    }

    @Override
    public String getNameById(Long id) {
        List<SocietiesType> societiesTypes =
                this.getBaseMapper().selectList(new LambdaQueryWrapper<SocietiesType>().eq(SocietiesType::getId, id));
        if (CollUtil.isNotEmpty(societiesTypes)) {
            return societiesTypes.get(0).getName();
        }
        return "";
    }
}
